home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / INTERVIE / GRAPHIC / HASH.H < prev    next >
C/C++ Source or Header  |  1991-12-10  |  3KB  |  76 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /*
  24.  * Hash table class for storing painters.  On X10, SetColor, SetFont, etc.
  25.  * operations require a client-server ipc round-trip and hence are
  26.  * inefficient.  To avoid this, we keep a hash table of painters that have
  27.  * preset colors, patterns, etc.  When it's time to Draw a graphic, we
  28.  * use a painter whose graphics state matches the graphic's own.  If none
  29.  * exists, then we create a new painter, set its graphics state to match
  30.  * the graphic's, and use it to draw the graphic.  The new painter is stored
  31.  * in the hash table for future use.
  32.  */
  33.  
  34. #ifndef hash_h
  35. #define hash_h
  36.  
  37. class Entry;
  38. class Graphic;
  39. class Painter;
  40.  
  41. class HashTable {
  42. public:
  43.     HashTable(int);
  44.     ~HashTable();
  45.  
  46.     void Insert(void* tag, void* value);
  47.     void Remove(void* tag);
  48.     void* Find(void* tag);
  49. protected:
  50.     virtual boolean Match(void* target, void* entry);
  51.     virtual int Hash(void*);
  52. protected:
  53.     Entry** entries;
  54.     int count;
  55. };
  56.  
  57. class GraphicToPainter : public HashTable {
  58. public:
  59.     GraphicToPainter(int);
  60.     ~GraphicToPainter();
  61.  
  62.     void Insert(Graphic*, Painter*&);
  63.     void Remove(Graphic* g) { HashTable::Remove(g); }
  64.     Painter* Find(Graphic* g);
  65.     void Clip(Canvas*, Coord, Coord, Coord, Coord);
  66.     void NoClip();
  67. private:
  68.     boolean Match(void*, void*);
  69.     int Hash(void*);
  70. private:
  71.     class Canvas* canvas;
  72.     class BoxObj* box;
  73. };
  74.  
  75. #endif
  76.